package com.cuit.dao;

import com.cuit.doamin.Recruitment;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RecruitmentDao {
    /**
     * 增加并发布一个招聘信息
     *
     * @return
     */
    @Insert("insert into recruitment (r_type,r_details) values (#{r_type},#{r_details})")
    public boolean add(Recruitment recruitment);

    /**
     * 删除招聘信息
     *
     * @return
     */
    @Delete("delete from recruitment where r_id = #{id}")
    public boolean delete(Integer id);

    /**
     * 查询招聘信息
     *
     * @return
     */
    @Select("select * from recruitment")
    public List<Recruitment> find();

    /**
     * 根据用户ID查询招聘信息，此处用到recruitment和r_u两个表
     *
     * @return
     */
    @Select("select * from recruitment r LEFT OUTER JOIN r_u on r_id = rid where uid = #{id}")
    public List<Recruitment> findByUid(Integer id);

    /**
     * 查询所有招聘信息的应聘简历
     *
     * @return
     */
    @Select("select * from recruitment")
    @Results(id = "recruitMap", value = {
            @Result(id = true, property = "r_id", column = "r_id"),
            @Result(property = "r_type", column = "r_type"),
            @Result(property = "r_details", column = "r_details"),
            @Result(property = "users", column = "r_id",
                    many = @Many(
                            select = "com.cuit.dao.UserDao.findByRid",
                            fetchType = FetchType.LAZY
                    )
            )
    })
    public List<Recruitment> findPost();
}
